package com.mxdx.edu.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.mxdx.base.service.facade.IFileUploadServiceFacade;
import com.mxdx.edu.common.ApiResult;
import com.mxdx.edu.common.CommonUtils;
import com.mxdx.edu.common.log.AppLogger;
import com.mxdx.edu.enums.CreateTypeEnums;
import com.mxdx.edu.enums.ErrorEnums;
import com.mxdx.edu.model.FamilyMembeInfo;
import com.mxdx.edu.model.LearningExperienceInfo;
import com.mxdx.edu.model.SchoolStatusInfo;
import com.mxdx.edu.service.ICacheService;
import com.mxdx.edu.service.IFamilyMembeInfoService;
import com.mxdx.edu.service.ILearningExperienceInfoService;
import com.mxdx.edu.util.ServletUtil;
import com.mxdx.edu.util.StringUtils;

/**
 * 学籍管理
 * 
 * @author wangyuan
 *
 */

@Controller
@RequestMapping(value = "/schoolroll")
public class SchoolRollController extends BaseController {

	private AppLogger logger = new AppLogger(SchoolRollController.class);

	@Resource
	private ICacheService cacheService;

	@Resource
	private IFileUploadServiceFacade fileUploadServiceFacade;

	@Resource
	private IFamilyMembeInfoService familyMembeInfoService;

	@Resource
	private ILearningExperienceInfoService learningExperienceInfoService;

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/auth/typeIn")
	public ModelAndView typeIn(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mav = new ModelAndView("h5/xueji");
		SchoolStatusInfo ssi = schoolStatusService
				.getByStudentId(super.getStudentId(request)); // super.getStudentId(request)
		if (ssi != null) {
			mav.addObject("ssi", ssi);
		}

		String token = sessionUtil.getTokenSession(request);
		Map<String, Object> studentMap = (Map<String, Object>) redisUtil
				.get(token);
		String mood = CommonUtils.getStrValueFromMap(studentMap, "mood", "");
		String studentName = CommonUtils.getStrValueFromMap(studentMap,
				"studentName", "");
		String headPortrait = CommonUtils.getStrValueFromMap(studentMap,
				"headPortrait", "");
		mav.addObject("mood", mood);
		mav.addObject("studentName", studentName);
		mav.addObject("headPortrait", headPortrait);

		return mav;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/auth/registerSchool")
	public ModelAndView registerSchool(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mav = new ModelAndView("h5/baokaoyuanxiao");
		SchoolStatusInfo ssi = schoolStatusService
				.getByStudentId(super.getStudentId(request)); // super.getStudentId(request)
		if (ssi != null) {
			mav.addObject("ssi", ssi);
		}

		String token = sessionUtil.getTokenSession(request);
		Map<String, Object> studentMap = (Map<String, Object>) redisUtil
				.get(token);
		String mood = CommonUtils.getStrValueFromMap(studentMap, "mood", "");
		String studentName = CommonUtils.getStrValueFromMap(studentMap,
				"studentName", "");
		String headPortrait = CommonUtils.getStrValueFromMap(studentMap,
				"headPortrait", "");

		mav.addObject("mood", mood);
		mav.addObject("studentName", studentName);
		mav.addObject("headPortrait", headPortrait);
		mav.addObject("gradeList", cacheService.getDictList("grade"));
		mav.addObject("levelList", cacheService.getDictList("level"));
		mav.addObject("learningFormList",
				cacheService.getDictList("learning_form"));
		mav.addObject("schoolingLengthList",
				cacheService.getDictList("schooling_length"));
		mav.addObject("fillDate",
				new SimpleDateFormat("yyyy-MM").format(new Date()));

		return mav;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/auth/profile")
	public ModelAndView profile(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mav = new ModelAndView("h5/gerenxinxi");
		SchoolStatusInfo ssi = schoolStatusService
				.getByStudentId(super.getStudentId(request));// super.getStudentId(request)
		if (ssi != null) {
			mav.addObject("ssi", ssi);
		}

		String token = sessionUtil.getTokenSession(request);
		Map<String, Object> studentMap = (Map<String, Object>) redisUtil
				.get(token);
		String mood = CommonUtils.getStrValueFromMap(studentMap, "mood", "");
		String studentName = CommonUtils.getStrValueFromMap(studentMap,
				"studentName", "");
		String headPortrait = CommonUtils.getStrValueFromMap(studentMap,
				"headPortrait", "");
		mav.addObject("mood", mood);
		mav.addObject("studentName", studentName);
		mav.addObject("headPortrait", headPortrait);
		mav.addObject("imageHost", imageHost);
		mav.addObject("learningFormList",
				cacheService.getDictList("learning_form"));
		mav.addObject("educationDegreeList",
				cacheService.getDictList("education_degree"));
		mav.addObject("politicalOutlookList",
				cacheService.getDictList("political_outlook"));
		mav.addObject("householdNatureList",
				cacheService.getDictList("household_registration_nature"));

		return mav;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/auth/workerInfo")
	public ModelAndView workerInfo(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView modelAndView = new ModelAndView("h5/gongzuojingli");

		
		SchoolStatusInfo ssi = schoolStatusService
				.getByStudentId(super.getStudentId(request));// super.getStudentId(request)
		if (ssi != null) {
			modelAndView.addObject("ssi", ssi);
		}
		
		Map<String, Object> map = new HashMap<>();
		map.put("studentId", super.getStudentId(request));
		List<LearningExperienceInfo> list = learningExperienceInfoService
				.selectLearningExperienceInfo(map);

		for (LearningExperienceInfo temp : list) {
			if (temp.getExperienceType().equals("1")) { // 小学
				modelAndView.addObject("primary", temp);
			}
			if (temp.getExperienceType().equals("2")) { // 初中
				modelAndView.addObject("junior", temp);
			}
			if (temp.getExperienceType().equals("3")) { // 高中
				modelAndView.addObject("senior", temp);
			}
			if (temp.getExperienceType().equals("4")) { // 大学
				modelAndView.addObject("college", temp);
			}
			if (temp.getExperienceType().equals("5")) { // 工作1
				modelAndView.addObject("work1", temp);
			}
			if (temp.getExperienceType().equals("6")) { // 工作1
				modelAndView.addObject("work2", temp);
			}
			if (temp.getExperienceType().equals("7")) { // 工作1
				modelAndView.addObject("work3", temp);
			}
		}

		String token = sessionUtil.getTokenSession(request);
		Map<String, Object> studentMap = (Map<String, Object>) redisUtil
				.get(token);
		String mood = CommonUtils.getStrValueFromMap(studentMap, "mood", "");
		String studentName = CommonUtils.getStrValueFromMap(studentMap,
				"studentName", "");
		String headPortrait = CommonUtils.getStrValueFromMap(studentMap,
				"headPortrait", "");
		modelAndView.addObject("mood", mood);
		modelAndView.addObject("studentName", studentName);
		modelAndView.addObject("headPortrait", headPortrait);
		modelAndView.addObject("studentId", super.getStudentId(request));

		return modelAndView;
	}

	@RequestMapping(value = "/auth/workerInfo/save")
	@ResponseBody
	public ApiResult<String> saveWorkerInfo(HttpServletRequest request,
			HttpServletResponse response) {
		logger.entry(ServletUtil.getClientIp(request), "saveWorkerInfo");
		Map<String, Object> logMap = new HashMap<>();
		ApiResult<String> apiResult = new ApiResult<>();

		String period = ServletUtil.getParameterStr(request, "period", "");
		String reterence = ServletUtil
				.getParameterStr(request, "reterence", "");
		String experienceType = ServletUtil.getParameterStr(request,
				"experienceType", "");
		String schoolOrWorkUnit = ServletUtil.getParameterStr(request,
				"schoolOrWorkUnit", "");

		logMap.put("period", period);
		logMap.put("reterence", reterence);
		logMap.put("experienceType", experienceType);
		logMap.put("schoolOrWorkUnit", schoolOrWorkUnit);

		LearningExperienceInfo learningExperienceInfo = new LearningExperienceInfo();
		learningExperienceInfo.setId(serialService.generateSerialNum(
				CreateTypeEnums.CREATE_STUDENT.getCode(), 6));
		learningExperienceInfo.setPeriod(period);
		learningExperienceInfo.setReterence(reterence);
		learningExperienceInfo.setStudentId(super.getStudentId(request));
		learningExperienceInfo.setExperienceType(experienceType);
		learningExperienceInfo.setSchoolOrWorkUnit(schoolOrWorkUnit);
		learningExperienceInfo.setCreateDate(new Date());
		learningExperienceInfo.setUpdateDate(new Date());

		boolean result = learningExperienceInfoService
				.save(learningExperienceInfo);
		logMap.put("result", result);
		if (!result) {
			apiResult.setStatus(ErrorEnums.SAVE_ERROR.getCode());
			apiResult.setMessage(ErrorEnums.SAVE_ERROR.getDesc());
			logger.error(logMap);
			return apiResult;
		}

		Map<String, Object> map = new HashMap<>();
		map.put("studentId", super.getStudentId(request));
		map.put("updateDate", new Date());
		map.put("workExperienceFillStatus", 1);
		schoolStatusService.updateSchoolStatus(map);

		logger.info(logMap);
		return apiResult;
	}

	@RequestMapping(value = "/auth/workerInfo/update")
	@ResponseBody
	public ApiResult<String> updateWorkerInfo(HttpServletRequest request,
			HttpServletResponse response) {
		logger.entry(ServletUtil.getClientIp(request), "updateWorkerInfo");
		Map<String, Object> logMap = new HashMap<>();
		ApiResult<String> apiResult = new ApiResult<>();

		String id = ServletUtil.getParameterStr(request, "id", "");
		String period = ServletUtil.getParameterStr(request, "period", "");
		String reterence = ServletUtil
				.getParameterStr(request, "reterence", "");
		String schoolOrWorkUnit = ServletUtil.getParameterStr(request,
				"schoolOrWorkUnit", "");

		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("period", period);
		param.put("reterence", reterence);
		param.put("schoolOrWorkUnit", schoolOrWorkUnit);

		logMap.putAll(param);
		boolean result = learningExperienceInfoService
				.mergeLearningExperienceInfo(param);
		logMap.put("result", result);
		if (!result) {
			apiResult.setStatus(ErrorEnums.UPDATE_ERROR.getCode());
			apiResult.setMessage(ErrorEnums.UPDATE_ERROR.getDesc());
			logger.error(logMap);
			return apiResult;
		}

		Map<String, Object> map = new HashMap<>();
		map.put("studentId", super.getStudentId(request));
		map.put("updateDate", new Date());
		map.put("workExperienceFillStatus", 1);
		schoolStatusService.updateSchoolStatus(map);

		logger.info(logMap);
		return apiResult;
	}

	@RequestMapping(value = "/auth/workerInfo/check")
	@ResponseBody
	public ApiResult<String> checkWorkerInfo(HttpServletRequest request,
			HttpServletResponse response) {
		logger.entry(ServletUtil.getClientIp(request), "checkWorkerInfo");
		Map<String, Object> logMap = new HashMap<>();
		ApiResult<String> apiResult = new ApiResult<>();
		
		String studentId = ServletUtil
				.getParameterStr(request, "studentId", "");
		
		Map<String, Object> param = new HashMap<>();
		param.put("studentId", studentId);

		try{
			TimeUnit.SECONDS.sleep(2);
		}catch(Exception e){
		}
		
		List<Map<String, Object>> listMap = learningExperienceInfoService
				.findLearningExperienceInfo(param);

		for (Map<String, Object> map : listMap) {
			if (null != map && map.keySet().size() > 0) {
				if ((null != map.get("schoolOrWorkUnit") && !StringUtils
						.isEmpty(map.get("schoolOrWorkUnit").toString()))
						|| (null != map.get("period") && !StringUtils
								.isEmpty(map.get("period").toString()))
						|| (null != map.get("reterence") && !StringUtils
								.isEmpty(map.get("reterence").toString()))) {
					apiResult.setMessage("不需要更新0");
					return apiResult;
				}
			}
		}

		Map<String, Object> map = new HashMap<>();
		map.put("studentId", super.getStudentId(request));
		map.put("updateDate", new Date());
		map.put("workExperienceFillStatus", 0);
		schoolStatusService.updateSchoolStatus(map);

		logger.info(logMap);
		return apiResult;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/auth/familyInfo")
	public ModelAndView familyInfo(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView modelAndView = new ModelAndView("h5/jiatingxinxi");

		SchoolStatusInfo ssi = schoolStatusService
				.getByStudentId(super.getStudentId(request));// super.getStudentId(request)
		if (ssi != null) {
			modelAndView.addObject("ssi", ssi);
		}
		
		Map<String, Object> map = new HashMap<>();
		map.put("studentId", super.getStudentId(request));
		List<FamilyMembeInfo> list = familyMembeInfoService
				.selectFamilyMembeInfo(map);

		for (FamilyMembeInfo temp : list) {
			if (temp.getAppellation().equals("1")) {
				modelAndView.addObject("father", temp);
			}
			if (temp.getAppellation().equals("2")) {
				modelAndView.addObject("mather", temp);
			}
			if (temp.getAppellation().equals("3")) {
				modelAndView.addObject("wife", temp);
			}
			if (temp.getAppellation().equals("4")) {
				modelAndView.addObject("child", temp);
			}
		}

		String token = sessionUtil.getTokenSession(request);
		Map<String, Object> studentMap = (Map<String, Object>) redisUtil
				.get(token);
		String mood = CommonUtils.getStrValueFromMap(studentMap, "mood", "");
		String studentName = CommonUtils.getStrValueFromMap(studentMap,
				"studentName", "");
		String headPortrait = CommonUtils.getStrValueFromMap(studentMap,
				"headPortrait", "");
		modelAndView.addObject("mood", mood);
		modelAndView.addObject("studentId", super.getStudentId(request));
		modelAndView.addObject("studentName", studentName);
		modelAndView.addObject("headPortrait", headPortrait);

		return modelAndView;
	}

	@RequestMapping(value = "/auth/familyInfo/save")
	@ResponseBody
	public ApiResult<String> saveFamilyInfo(HttpServletRequest request,
			HttpServletResponse response) {
		logger.entry(ServletUtil.getClientIp(request), "saveFamilyInfo");
		Map<String, Object> logMap = new HashMap<>();
		ApiResult<String> apiResult = new ApiResult<>();

		String memberName = ServletUtil.getParameterStr(request, "memberName",
				"");
		String age = ServletUtil.getParameterStr(request, "age", "");
		String appellation = ServletUtil.getParameterStr(request,
				"appellation", "");
		String politicalOutlook = ServletUtil.getParameterStr(request,
				"politicalOutlook", "");
		String workingUnit = ServletUtil.getParameterStr(request,
				"workingUnit", "");
		String contactPhone = ServletUtil.getParameterStr(request,
				"contactPhone", "");

		logMap.put("memberName", memberName);
		logMap.put("age", age);
		logMap.put("politicalOutlook", politicalOutlook);
		logMap.put("workingUnit", workingUnit);
		logMap.put("contactPhone", contactPhone);

		FamilyMembeInfo familyMembeInfo = new FamilyMembeInfo();
		familyMembeInfo.setId(serialService.generateSerialNum(
				CreateTypeEnums.CREATE_STUDENT.getCode(), 6));
		familyMembeInfo.setMemberName(memberName);
		familyMembeInfo.setAge(age);
		familyMembeInfo.setStudentId(super.getStudentId(request));
		familyMembeInfo.setAppellation(appellation);
		familyMembeInfo.setPoliticalOutlook(politicalOutlook);
		familyMembeInfo.setContactPhone(contactPhone);
		familyMembeInfo.setWorkingUnit(workingUnit);

		familyMembeInfo.setCreateDate(new Date());
		familyMembeInfo.setUpdateDate(new Date());

		boolean result = familyMembeInfoService.save(familyMembeInfo);
		logMap.put("result", result);
		if (!result) {
			apiResult.setStatus(ErrorEnums.SAVE_ERROR.getCode());
			apiResult.setMessage(ErrorEnums.SAVE_ERROR.getDesc());
			logger.error(logMap);
			return apiResult;
		}

		Map<String, Object> map = new HashMap<>();
		map.put("studentId", super.getStudentId(request));
		map.put("updateDate", new Date());
		map.put("familyFillStatus", 1);
		schoolStatusService.updateSchoolStatus(map);

		logger.info(logMap);
		return apiResult;
	}

	@RequestMapping(value = "/auth/familyInfo/update")
	@ResponseBody
	public ApiResult<String> updateFamilyInfo(HttpServletRequest request,
			HttpServletResponse response) {
		logger.entry(ServletUtil.getClientIp(request), "updateFamilyInfo");
		Map<String, Object> logMap = new HashMap<>();
		ApiResult<String> apiResult = new ApiResult<>();

		String id = ServletUtil.getParameterStr(request, "id", "");
		String memberName = ServletUtil.getParameterStr(request, "memberName",
				"");
		String age = ServletUtil.getParameterStr(request, "age", "");
		String politicalOutlook = ServletUtil.getParameterStr(request,
				"politicalOutlook", "");
		String workingUnit = ServletUtil.getParameterStr(request,
				"workingUnit", "");
		String contactPhone = ServletUtil.getParameterStr(request,
				"contactPhone", "");

		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("memberName", memberName);
		param.put("age", age);
		param.put("workingUnit", workingUnit);
		param.put("contactPhone", contactPhone);
		param.put("politicalOutlook", politicalOutlook);

		logMap.putAll(param);
		boolean result = familyMembeInfoService.mergeFamilyMembeInfo(param);

		logMap.put("result", result);
		if (!result) {
			apiResult.setStatus(ErrorEnums.UPDATE_ERROR.getCode());
			apiResult.setMessage(ErrorEnums.UPDATE_ERROR.getDesc());
			logger.error(logMap);
			return apiResult;
		}

		Map<String, Object> map = new HashMap<>();
		map.put("studentId", super.getStudentId(request));
		map.put("updateDate", new Date());
		map.put("familyFillStatus", 1);
		schoolStatusService.updateSchoolStatus(map);

		logger.info(logMap);
		return apiResult;
	}
	
	@RequestMapping(value = "/auth/familyInfo/check")
	@ResponseBody
	public ApiResult<String> checkFamilyInfo(HttpServletRequest request,
			HttpServletResponse response) {
		logger.entry(ServletUtil.getClientIp(request), "checkFamilyInfo");
		Map<String, Object> logMap = new HashMap<>();
		ApiResult<String> apiResult = new ApiResult<>();

		String studentId = ServletUtil
				.getParameterStr(request, "studentId", "");

		Map<String, Object> param = new HashMap<>();
		param.put("studentId", studentId);
		
		try{
			TimeUnit.SECONDS.sleep(2);
		}catch(Exception e){
		}
		
		List<Map<String, Object>> listMap = familyMembeInfoService.findFamilyMembeInfo(param);

		for (Map<String, Object> map : listMap) {
			if (null != map && map.keySet().size() > 0) {
				if ((null != map.get("contactPhone") && !StringUtils
						.isEmpty(map.get("contactPhone").toString()))
						|| (null != map.get("politicalOutlook") && !StringUtils
								.isEmpty(map.get("politicalOutlook").toString()))
						|| (null != map.get("age") && !StringUtils
								.isEmpty(map.get("age").toString()))
								||(null != map.get("workingUnit") && !StringUtils
										.isEmpty(map.get("workingUnit").toString()))
										||(null != map.get("memberName") && !StringUtils
										.isEmpty(map.get("memberName").toString()))) {
					apiResult.setMessage("不需要更新0");
					return apiResult;
				}
			}
		}

		Map<String, Object> map = new HashMap<>();
		map.put("studentId", studentId);
		map.put("updateDate", new Date());
		map.put("familyFillStatus", 0);
		boolean result = schoolStatusService.updateSchoolStatus(map);
		logMap.put("result", result);
		logger.info(logMap);
		return apiResult;
	}

	@RequestMapping(value = "/auth/update")
	@ResponseBody
	@SuppressWarnings("unchecked")
	public ApiResult<String> updateSchoolStatusInfo(HttpServletRequest request,
			HttpServletResponse response, SchoolStatusInfo schoolStatusInfo) {
		logger.entry(request.getRemoteHost(), "updateSchoolStatusInfo");
		ApiResult<String> apiResult = new ApiResult<>();
		JSONObject json = (JSONObject) JSONObject.toJSON(schoolStatusInfo);

		if (json.containsKey("email")
				&& !StringUtils.isEmpty(json.getString("email"))) {
			if (!StringUtils.isEmail(json.getString("email"))) { // 验证邮箱地址
				apiResult.setStatus(ErrorEnums.EMAIL_FORMAT_ERROR.getCode());
				apiResult.setMessage(ErrorEnums.EMAIL_FORMAT_ERROR.getDesc());
				return apiResult;
			}
		}

		Map<String, Object> map = JSONObject.toJavaObject(json, Map.class);
		map.put("studentId", super.getStudentId(request));
		if((map.containsKey("nation") && null != map.get("nation")) || (map.containsKey("marriage") && null != map.get("marriage")) || 
				(map.containsKey("politicalOutlook") && null != map.get("politicalOutlook")) || 
				(map.containsKey("originPlace") && null != map.get("originPlace")) || 
				(map.containsKey("preSchoolEducation") && null != map.get("preSchoolEducation")) || 
				(map.containsKey("homeAddress") && null != map.get("homeAddress")) || 
				(map.containsKey("workUnit") && null != map.get("workUnit")) || 
				(map.containsKey("postalCode") && null != map.get("postalCode")) || 
				(map.containsKey("post") && null != map.get("post")) || 
				(map.containsKey("otherContactPhone") && null != map.get("otherContactPhone")) ||
				(map.containsKey("postalAddress") && null != map.get("postalAddress")) ||
				(map.containsKey("sex") && null != map.get("sex"))){
			map.put("baseInfoFillStatus", 1);
		}
		
		map.remove("familyFillStatus");
		map.remove("workExperienceFillStatus"); // 这几个状态不在这里处理
		boolean result = schoolStatusService.mergeSchoolStatus(map);
		if (!result) {
			apiResult.setStatus(ErrorEnums.UPDATE_ERROR.getCode());
			apiResult.setMessage(ErrorEnums.UPDATE_ERROR.getDesc());
		}
		return apiResult;
	}

	@RequestMapping(value = "/auth/uploadPic", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> handleUploadProcess(HttpServletRequest request) {
		logger.entry(request.getRemoteHost(), "handleUploadProcess");
		Map<String, Object> logMap = new HashMap<>();
		Map<String, Object> returnMap = new HashMap<>();
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		String fileName = "";
		try {
			for (Iterator<?> it = multipartRequest.getFileNames(); it.hasNext();) {
				String key = (String) it.next();
				List<MultipartFile> mulfiles = multipartRequest.getFiles(key); // 一个上传控件上传多张图片
				for (MultipartFile file : mulfiles) {
					if (file.getSize() == 0) {
						returnMap.put("msg", "请选择上传文件");
						return returnMap;
					}
					String name = file.getOriginalFilename();
					String suffix = name.substring(name.lastIndexOf(".") + 1,
							name.length());
					logMap.put("name", name);
					logMap.put("suffix", suffix);
					ApiResult<Map<String, String>> ret = fileUploadServiceFacade
							.saveFile("mxdx", suffix, file.getInputStream());
					String status = ret.getStatus();
					logMap.put("status", status);
					logger.doInfo("上传文件结果", ret);
					if ("00000000".equals(status)) {
						fileName = ret.getResult().get("saveFilename");
					}
				}
			}
			returnMap.put("msg", "success");
			returnMap.put("fileName", fileName);
			returnMap.put("imageUrl",
					String.format("%s%s", imageHost, fileName));

			logMap.putAll(returnMap);
			logger.info(logMap);

			return returnMap;
		} catch (Exception e) {
			e.printStackTrace();
			returnMap.put("msg", "failed");
			logMap.putAll(returnMap);
			logger.error(logMap);
			return returnMap;
		}
	}

}
